/**
 * @author Tobias Boehm
 *
 * 03.06.2011
 */
package org.anddev.andengine.extension.tbsengine.message.server.ingame;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.anddev.andengine.extension.tbsengine.match.AbsMatch.MatchState;
import org.anddev.andengine.extension.tbsengine.message.ICopyable;
import org.anddev.andengine.extension.tbsengine.message.server.AbsServerMatchMessage;

/**
 * This message should be used to announce a {@link MatchState} change to
 * corresponding players.
 * 
 * @author Tobias Boehm
 *
 */
public class ServerMatchStateChangedAnnouncementMessage extends AbsServerMatchMessage implements ICopyable<ServerMatchStateChangedAnnouncementMessage> {

	private MatchState mMatchState;
	
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_SERVER_MATCH_STATE_CHANGED_ANNOUNCEMENT;
	}

	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.tbsengine.server.messages.shared.AbsServerMatchMessage#onReadTransmissonMatchData(java.io.DataInputStream)
	 */
	@Override
	protected void onReadTransmissonMatchData(DataInputStream pDataInputStream)
			throws IOException {
		
		this.mMatchState = MatchState.valueOf(pDataInputStream.readUTF());

	}

	
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.tbsengine.server.messages.shared.AbsServerMatchMessage#onWriteTransmissonMatchData(java.io.DataOutputStream)
	 */
	@Override
	protected void onWriteTransmissonMatchData(final DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeUTF(this.mMatchState.name());
	}

	@Override
	public ServerMatchStateChangedAnnouncementMessage copy() {
		
		final ServerMatchStateChangedAnnouncementMessage copy = new ServerMatchStateChangedAnnouncementMessage();
		
		copy.mMatchID = this.mMatchID;
		
		return copy;
		
	}

}
